<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        button {
            padding: 3px 10px;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <button @click='add1'>点击1</button><span> a:值为 </span><span> {{a}} </span>

        </div>
        <div>
            <button @click='add2'>点击2</button> <span> b:值为 </span><span> {{b}} </span>
        </div>
        <div>
            computed
            <span>total:值为</span><span>{{total}}</span>
        </div>
    </div>
    <script src="/vue/computed.js"></script>

    <script src="/vue/index.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data() {
                return {
                    a: 1,
                    b: 2,
                }
            },
            methods: {
                add1() {
                    this.a++;
                    console.log(this.a);
                },
                add2() {
                    this.b++
                }
            },
            computed: {
                total() {
                    return this.a + this.b
                }
            },
            watch: {
                total(newVal, oldVal) {
                    console.log('total', newVal, oldVal)
                },
                a(newVal, oldVal) {
                    console.log('a', newVal, oldVal)
                },
                b(newVal, oldVal) {
                    console.log('b', newVal, oldVal)
                },
            }
        })
        console.log(app);

    </script>
</body>

</html>